<?php 
// 中文编码
header('content-type:text/html;charset=utf-8;');
$link=mysqli_connect('127.0.0.1','root','root','mi');
$username=$_REQUEST['un'];
$password=$_REQUEST['pw'];

// echo $username,$password;
//查询数据库
$sql = "SELECT * FROM `userinfo` WHERE `username`='$username' AND `password`='$password' ";
$arr=mysqli_query($link,$sql);
//解析
$res=mysqli_fetch_all($arr);
if($res){
    //表示存在
    //登录成功，记录cookie
    setcookie('username', $username);
    $new_arr = array('code' => 1);
}else{
    $new_arr = array('code' => 0);
}
echo $jsonstr=json_encode($new_arr);